﻿using System.Windows;
using DataSentryPro_R2.ViewModel;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;

namespace DataSentryPro_R2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Closing += (s, e) => ViewModelLocator.Cleanup();


        }



        #region Command Processing //+ Command Processing

                                                                                                                                                                                                                #region Mouse Enter Events //+ Mouse Enter Events 

    private void controlManagement_MouseEnter(object sender, MouseEventArgs e)
        {

        #region Object Detection
            
            // Find out what type of Object it its
        System.Type type = sender.GetType();

        // Cast the Sender tot he appropriate Type to get access to properties

        // Access Name of Object
        string myObjectName = "";

        if (type == typeof(Grid))
        {
            Grid myObject = (Grid)sender;
            myObjectName = myObject.Name;
        }

        else if (type == typeof(Image))
        {

            Image myObject = (Image)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(TextBlock))
        {

            TextBlock myObject = (TextBlock)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(Border))
        {

            Border myObject = (Border)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(Rect))
        {

            Border myObject = (Border)sender;
            myObjectName = myObject.Name;

        }

            
        // Get Object Name 
        System.Console.WriteLine("Sending Object Name = " + myObjectName);

        // Initialize StoryBoard
        Storyboard SB;
            #endregion

        switch (myObjectName)
        {

            //! Show Selected Effect

            case "imgMinimizeWindow":

                // Apply the effect to the calling object
        
                SB = (Storyboard)this.FindResource("aniMinimize");
                SB.Begin();

                // End

                break;

            case "imgMaximizeWindow":

                // Apply the effect to the calling object
                
                SB = (Storyboard)this.FindResource("aniMaximize");
                SB.Begin();

                // End
                
                break;


            case "imgCloseWindow":

                // Apply the effect to the calling object

                SB = (Storyboard)this.FindResource("aniClose");
                SB.Begin();

                // End
                
                break;

            //BMK Mouse ENTER 

            default:

                // End
                break;

        }
    }

    #endregion // MouseEnter


                                                                                                                                                                                                            #region Mouse Leave Events //+ Mouse Leave Events

    private void controlManagement_MouseLeave(object sender, MouseEventArgs e)
    {

        #region Object Detection
        

        // Find out what type of Object it its
        System.Type type = sender.GetType();

        // Cast the Sender tot he appropriate Type to get access to properties

        // Access Name of Object
        string myObjectName = "";

        if (type == typeof(Grid))
        {
            Grid myObject = (Grid)sender;
            myObjectName = myObject.Name;
        }

        else if (type == typeof(Image))
        {

            Image myObject = (Image)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(TextBlock))
        {

            TextBlock myObject = (TextBlock)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(Border))
        {

            Border myObject = (Border)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(Rect))
        {

            Border myObject = (Border)sender;
            myObjectName = myObject.Name;

        }


        // Get Object Name 
        System.Console.WriteLine("Sending Object Name = " + myObjectName);

        // Initialize StoryBoard
        Storyboard SB;

        #endregion

        switch (myObjectName)
        {

            //! Reverse Selected Effect

            case "imgMinimizeWindow":

                // Apply the effect to the calling object
            
                SB = (Storyboard)this.FindResource("aniMinimize_R");
                SB.Begin();
                
                // End

                break;


            //! Reverse Selected Effect

            case "imgMaximizeWindow":

                // Apply the effect to the calling object
  
                SB = (Storyboard)this.FindResource("aniMaximize_R");
                SB.Begin();

                // End

                break;


            case "imgCloseWindow":

                // Apply the effect to the calling object

                SB = (Storyboard)this.FindResource("aniClose_R");
                SB.Begin();

                // End

                break;


            //BMK Mouse LEAVE


            default:

                // End
                break;

        }
    }

    #endregion // Mouse Leave

                                                                                                                                                                                                                                                                                        #region Mouse Down Events //+ Mouse Down Events
        
    private void controlManagement_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {


        #region Object Detection
        
        // Find out what type of Object it its
        System.Type type = sender.GetType();

        // Cast the Sender tot he appropriate Type to get access to properties

        // Access Name of Object
        string myObjectName = "";

        if (type == typeof(Grid))
        {
            Grid myObject = (Grid)sender;
            myObjectName = myObject.Name;
        }

        else if (type == typeof(Image))
        {

            Image myObject = (Image)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(TextBlock))
        {

            TextBlock myObject = (TextBlock)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(Border))
        {

            Border myObject = (Border)sender;
            myObjectName = myObject.Name;

        }
        else if (type == typeof(Rectangle))
        {

            Rectangle myObject = (Rectangle)sender;
            myObjectName = myObject.Name;

        }

        // Get Object Name 
        System.Console.WriteLine("Sending Object Name = " + myObjectName);

        #endregion

        switch (myObjectName)
        {

            //! Move the Window 

            case "rectMoveWindow":

                    

                this.DragMove();

                // End
                    
                break;

            //! Terminate the Program 

            case "imgCloseWindow":

                Application.Current.Shutdown();

                // End
                    
                break;


            //! Minimize Window

            case "imgMinimizeWindow":

                this.WindowState = WindowState.Minimized;

                // End

                break;

            //! Maximize Window

            case "imgMaximizeWindow":

                // Check if the Window is already Maximized First

                if (this.WindowState == WindowState.Maximized)
                {
                    this.WindowState = WindowState.Normal;
                }
                else
                {

                    this.WindowState = WindowState.Maximized;
                }
                    

                // End

                break;

            //BMK Mouse DOWN

            default:

                // End
                break;

        }
    }


        #endregion // Mouse Down

        #endregion // All Mouse Events



        #region Button Control
        
        #endregion



    }
    
}
